package action

import (
	"core/action"
	"core/corestruct"
	"core/myerrors"
	"ht/selfreg"
	htfileservice "ht/service/htfile"

	"reflect"
	"strconv"
)

type ShowAction struct {
}

func (p *ShowAction) Do(ctx *corestruct.HttpContext) error {

	var c = ctx.Http
	var sid = c.Query("id")
	if "" == sid {
		return myerrors.New("无效的请求")
	}
	var id, _ = strconv.ParseInt(sid, 10, 64)

	var svr = htfileservice.HtfileService{}
	data, err := svr.GetShow(id)
	if err != nil {
		return err
	}
	c.Header("Content-Type", data.ContentType)
	c.Status(200)
	c.Writer.Write(*data.Data)
	return nil

}

func init() {
	var mact = &ShowAction{}
	var maction = action.Action{
		Method: "",

		FullUrl: htfileservice.URLPrev + "/Show",
		Name:    "显示" + PAGEName,
		Ename:   "",
		Memo:    "",

		PinType:    "",
		PinIslist:  false,
		PoutType:   "",
		PoutIslist: false,
		PoutIspage: false,

		AuthType: action.AuthType_NONE,

		LogNeed:     false,
		LogPin:      false,
		LogPout:     false,
		LogTemplete: "",

		PrjName: "",

		Value: reflect.ValueOf(mact),
	}
	selfreg.AddAction(&maction)

}
